define(['store'],function (store) {
    'use strict';
    function ctrl($scope,$state,WTService, LocalCacheService,$ionicLoading, CommonService, DeviceService,IdentificationService) {
        var userInfo = LocalCacheService.getUser();
        function init() {
            $scope.user = {
                name: userInfo.client_name
            }
        }

        $scope.$on('$ionicView.beforeEnter', function () {
            init()
        });

        $scope.video = function () {
            //视频验证成功返回
            var params = {
                user_id: userInfo.user_id,
                client_name:userInfo.client_name,
                branch_no:userInfo.branch_no,
                businessNumber: '6'
            };

            DeviceService.asyncVideo(params, function (data) {
                $ionicLoading.show();
                if (data.error_no == 0) {
                    WTService.resetMobile('5').then(
                        function (data) {
                            $ionicLoading.hide();
                            if (data.error_no != 0) {
                                CommonService.showAlert({message: data.error_info});
                                return;
                            }
                            var user=LocalCacheService.getUser();
                            user.mobile_tel=store.get('idCardCheck').mobile_tel;
                            LocalCacheService.setUser(user);
                            CommonService.showComplete('../view/template/phonetemplate.html', '返回', 'tab.account-manager');
                        },
                        function (result) {
                            $ionicLoading.hide();
                            CommonService.showAlert({message: CommonService.getErrorInfo(result)});
                        }
                    );
                } else if (data.error_no == 2) {
                    var params = {
                        status:'4'
                    };
                    IdentificationService.uploadCheckSumbit(params)
                        .then(function (data) {
                                $ionicLoading.hide();
                                if (data.error_no != 0) {
                                    CommonService.showAlert({message: data.error_info});
                                    return;
                                }
                                $state.go('tab.account-resetPhoneSecond');
                            }, function(result){
                                $ionicLoading.hide();
                                CommonService.showAlert({message: result.error_info});
                            }
                        );
                } else{
                    $ionicLoading.hide();
                    if (data.errorInfo) {
                        CommonService.showAlert({message: data.errorInfo});
                    }
            }
            })
        }
    }

    ctrl.$inject = ['$scope', '$state', 'WTService', 'LocalCacheService','$ionicLoading', 'CommonService', 'DeviceService','IdentificationService'];
    return ctrl;
});